package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.BuyFirstCollection;
import com.sc.nft.entity.BuyFirstUser;
import com.sc.nft.entity.vo.BuyFirstUserListVO;
import com.sc.nft.mapper.BuyFirstUserMapper;
import lombok.extern.slf4j.Slf4j;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (sc_buy_first_user)数据DAO
 *
 * @author rdg
 * @since 2022-08-03 15:19:27
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class BuyFirstUserDao extends ServiceImpl<BuyFirstUserMapper, BuyFirstUser> {

    public Page<BuyFirstUserListVO> buyFirstUserList(Long productId, String userTel, int pageNo, int pageSize) {
        return baseMapper.buyFirstUserList(productId,userTel,new Page(pageNo,pageSize));
    }

    public BuyFirstUser selectByProductIdAndUserId(Long productId, Long userId) {
        LambdaQueryWrapper<BuyFirstUser>wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(BuyFirstUser::getProductId,productId);
        wrapper.eq(BuyFirstUser::getUserBuyFirstId,userId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    public Boolean getIsExistByProductId(Long productId) {
        LambdaQueryWrapper<BuyFirstUser> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BuyFirstUser::getProductId, productId);
        return count(wrapper) > 0;
    }
}